package com.bookstore.controller;

import com.bookstore.common.Result;
import com.bookstore.entity.Review;
import com.bookstore.service.ReviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/review")
@Api(tags = "评论管理接口")
public class ReviewController {

    @Autowired
    private ReviewService reviewService;

    @PostMapping
    @ApiOperation("添加评论")
    public Result<Boolean> addReview(@RequestBody Review review) {
        return Result.success(reviewService.addReview(review));
    }

    @PutMapping
    @ApiOperation("更新评论")
    public Result<Boolean> updateReview(@RequestBody Review review) {
        return Result.success(reviewService.updateReview(review));
    }

    @DeleteMapping("/{reviewId}")
    @ApiOperation("删除评论")
    public Result<Boolean> deleteReview(
            @ApiParam("评论ID") @PathVariable Integer reviewId) {
        return Result.success(reviewService.deleteReview(reviewId));
    }

    @GetMapping("/book/{bookId}")
    @ApiOperation("获取图书评论列表")
    public Result<List<Review>> getBookReviews(
            @ApiParam("图书ID") @PathVariable Integer bookId) {
        return Result.success(reviewService.getBookReviews(bookId));
    }

    @GetMapping("/user/{userId}")
    @ApiOperation("获取用户评论列表")
    public Result<List<Review>> getUserReviews(
            @ApiParam("用户ID") @PathVariable Integer userId) {
        return Result.success(reviewService.getUserReviews(userId));
    }

    @PutMapping("/{reviewId}/status")
    @ApiOperation("审核评论")
    public Result<Boolean> reviewStatus(
            @ApiParam("评论ID") @PathVariable Integer reviewId,
            @ApiParam("状态（1：通过，2：拒绝）") @RequestParam Integer status) {
        return Result.success(reviewService.reviewStatus(reviewId, status));
    }

    @PutMapping("/{reviewId}/like")
    @ApiOperation("点赞评论")
    public Result<Boolean> likeReview(
            @ApiParam("评论ID") @PathVariable Integer reviewId) {
        return Result.success(reviewService.likeReview(reviewId));
    }
} 